﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KenLib.BusinessManager;
using DataInfo;

public partial class JOINT_frmJ_TraineeResumeTranslate : System.Web.UI.Page
{
    応募情報Manager _応募情報Manager = new 応募情報Manager();

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Page load
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        txt_フリガナ氏.Focus();
        //Kiem tra session
        //Session["ID_frmJ_TraineeResumeAInput"] = 10;
        if (Session["ID_frmJ_TraineeResumeAInput"] == null)
        {
            Response.Redirect("frmJ_TraineeResumeAInput.aspx");
        }
        ((JOINT_MstPage_JOINT)this.Master).HideLiArea("frmJ_TraineeResumeTranslate");
        ((JOINT_MstPage_JOINT)this.Master).changeTitle("来社後　情報翻訳");
        RFV_フリガナ氏.ErrorMessage = GetError("ER00001");
        RFV_フリガナ名.ErrorMessage = GetError("ER00001");
        RFV_宗教.ErrorMessage = GetError("ER00001");
        RFV_民族.ErrorMessage = GetError("ER00001");
        //RFV_最終学歴.ErrorMessage = GetError("ER00001");
        RFV_家族構成.ErrorMessage = GetError("ER00001");
        RFV_在日親族状況.ErrorMessage = GetError("ER00001");
        RFV_趣味.ErrorMessage = GetError("ER00001");
        if (!IsPostBack)
        {
            ShowLabel();
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Go to page frmJ_TraineeInterviewList.aspx
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnキャンセル_Click(object sender, EventArgs e)
    {
        //txt_フリガナ氏.Text="";
        //txt_フリガナ名.Text="";
        //txt_宗教.Text="";
        //txt_民族.Text="";
        ////txt_最終学歴.Text="";
        //txt_家族構成.Text="";
        //txt_在日親族状況.Text="";
        //txt_趣味.Text="";
        Response.Redirect("frmJ_TraineeInterviewList.aspx");
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Update data in table 応募情報
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn登録完了_Click(object sender, EventArgs e)
    {

        string 姓_日本語 = ConvertHTMLtoText(txt_フリガナ氏.Text);
        string 名_日本語 = ConvertHTMLtoText(txt_フリガナ名.Text);
        string 宗教_日本語 = ConvertHTMLtoText(txt_宗教.Text);
        string 民族_日本語 = ConvertHTMLtoText(txt_民族.Text);
        //string 最終学歴_日本語 = ConvertHTMLtoText(txt_最終学歴.Text);
        string 家族構成_日本語 = ConvertHTMLtoText(txt_家族構成.Text);
        string 在日親族状況_日本語 = ConvertHTMLtoText(txt_在日親族状況.Text);
        string 趣味_日本語 = ConvertHTMLtoText(txt_趣味.Text);
        if (frmJ_TraineeResumeTranslate_update(Convert.ToInt32(Session["ID_frmJ_TraineeResumeAInput"]), 姓_日本語, 名_日本語, 宗教_日本語, 民族_日本語, 家族構成_日本語, 在日親族状況_日本語, 趣味_日本語) == 1)
        {
            Response.Redirect("frmJ_TraineeInterviewList.aspx");
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('データベースに接続ができません');</script>");
        }

    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Load data on lable
    /// </summary>
    public void ShowLabel()
    {
        DataTable dt = new DataTable();
        dt = _応募情報Manager.frmJ_TraineeResumeTranslate_SelectByID(Convert.ToInt32(Session["ID_frmJ_TraineeResumeAInput"]));
        if (dt.Rows.Count > 0)
        {
            //姓
            lbl_氏.Text = dt.Rows[0]["姓"].ToString();

            //名
            lbl_名.Text = dt.Rows[0]["名"].ToString();

            //フリガナ氏.Text
            txt_フリガナ氏.Text = dt.Rows[0]["姓_日本語"].ToString();

            //フリガナ名.Text
            txt_フリガナ名.Text = dt.Rows[0]["名_日本語"].ToString();

            //宗教 
            lbl_宗教.Text = dt.Rows[0]["宗教"].ToString();
            txt_宗教.Text = dt.Rows[0]["宗教_日本語"].ToString();

            //民族 
            lbl_民族.Text = dt.Rows[0]["民族"].ToString();
            txt_民族.Text = dt.Rows[0]["民族_日本語"].ToString();
            
            //最終学歴 
            lbl_最終学歴.Text = Show学歴区分(dt.Rows[0]["最終学歴"].ToString());

            //家族構成 
            lbl_家族構成.Text = dt.Rows[0]["家族構成"].ToString();
            txt_家族構成.Text = dt.Rows[0]["家族構成_日本語"].ToString();

            //在日親族有無 
            lbl_在日親族有無.Text = Show在日親族有無(dt.Rows[0]["在日親族有無"].ToString());

            //在日親族状況 
            lbl_在日親族状況.Text = dt.Rows[0]["在日親族状況"].ToString();
            txt_在日親族状況.Text = dt.Rows[0]["在日親族状況_日本語"].ToString();

            //趣味 
            lbl_趣味.Text = dt.Rows[0]["趣味"].ToString();
            txt_趣味.Text = dt.Rows[0]["趣味_日本語"].ToString();
        }
        else
        {
            Response.Redirect("frmJ_TraineeResumeAInput.aspx");
        }

    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Check update data in table 応募情報
    /// </summary>
    /// <param name="ID"></param>
    /// <param name="姓_日本語"></param>
    /// <param name="名_日本語"></param>
    /// <param name="宗教_日本語"></param>
    /// <param name="民族_日本語"></param>
    /// <param name="家族構成_日本語"></param>
    /// <param name="在日親族状況_日本語"></param>
    /// <param name="趣味_日本語"></param>
    /// <returns></returns>
    public int frmJ_TraineeResumeTranslate_update(int ID, string 姓_日本語, string 名_日本語, string 宗教_日本語, string 民族_日本語, string 家族構成_日本語, string 在日親族状況_日本語, string 趣味_日本語)
    {
        if (_応募情報Manager.frmJ_TraineeResumeTranslate_update(ID, 姓_日本語, 名_日本語, 宗教_日本語, 民族_日本語, 家族構成_日本語, 在日親族状況_日本語, 趣味_日本語) == 1)
        {
            return 1;
        }
        return 0;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Convert character html to text
    /// </summary>
    /// <param name="temp"></param>
    /// <returns></returns>
    public string ConvertHTMLtoText(string temp)
    {
        temp = temp.Replace("<", "&lt;");
        temp = temp.Replace(">", "&gt;");
        temp = temp.Replace(Convert.ToString((char)13), "<br/>");
        return temp;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Get error message from id
    /// </summary>
    /// <param name="errorid"></param>
    /// <returns></returns>
    public String GetError(string errorid)
    {
        string error = "";
        Error er = new Error();
        er.ErrorID = errorid;
        ErrorManager frm_error = new ErrorManager();
        DataTable dt = frm_error.getError(er);
        if (dt.Rows.Count > 0)
        {
            error = dt.Rows[0][2].ToString();
        }
        return error;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Convert number to string
    /// </summary>
    /// <param name="temp"></param>
    /// <returns></returns>
    public string Show学歴区分(string temp)
    {
        string strResult = "";
        switch (temp)
        {
            case "0":
                strResult = "博士";
                break;
            case "1":
                strResult = "修士";
                break;
            case "2":
                strResult = "学士";
                break;
            case "3":
                strResult = "高専";
                break;
            case "4":
                strResult = "高校";
                break;
            default:
                strResult = "中学";
                break;
        }
        return strResult;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Convert type bit to string
    /// </summary>
    /// <param name="temp"></param>
    /// <returns></returns>
    public string Show在日親族有無(string temp)
    {
        string strResult = "";
        if (temp == "")
        {
            strResult = "";
        }
        else if (temp == "true")
        {
            strResult = "有";
        }
        else
        {
            strResult = "無";
        }
        return strResult;
    }
}
